<?php
namespace Goatherd\Content\Engine\Reader;

use Goatherd\Content\Engine\Queue\IItem;

/**
 *
 */
class DeferedReaderContainer
{
    /**
     *
     * @var IItem
     */
    protected $_item;

    /**
     *
     * @var IReader
     */
    protected $_reader;

    /**
     *
     * @param IReader $reader
     * @param IItem $item
     */
    public function __construct(IReader $reader, IItem $item)
    {
        $this->_item = $item;
        $this->_reader = $reader;
    }

    /**
     *
     * @return \Closure
     */
    public function __invoke()
    {
        return function() {
            $rs = $this->_reader->getDefered($this->_item);
            return $rs;
        };
    }

    /**
     *
     * @param IReader $reader
     * @param IItem $item
     * @return ResourceContainer
     */
    public static function createResourceContainer(IReader $reader, IItem $item)
    {
        $obj = new static($reader, $item);
        $rc = ResourceContainer::create( $obj() );

        return $rc;
    }
}